﻿@model HmPMer.Entity.UserBaseInfo
@{
    ViewBag.Title = "修改密码";
    ViewBag.PageUri = "/center/safety";
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}

@section header{
    <link rel="stylesheet" type="text/css" href="/static/css/compiled/user-profile.css" media="screen" />
    <style>
        .alert-msg {
            display: none;
            margin-left: 5px;
        }
    </style>
}

<div class="container-fluid">
    <div id="pad-wrapper" class="form-page">

        <div class="row-fluid head">
            <div class="span12">
                <h4>二级密码修改</h4>
            </div>
        </div>

        <div class="row-fluid withdraw">

            <div class="field-box withdrawApply">
                <label>验证码:</label>
                <input class="span2 inline-input" placeholder="请输入右则图形验证码" type="text" id="ImgCode" maxlength="4" />
                <img id="img_code" src="/DrawingApi/GetValidateImg?codeKey=imgphonepwdvcode" alt="" onclick="this.src = '/DrawingApi/GetValidateImg?codeKey=imgphonepwdvcode&t=' + Math.random();" height="20" style="cursor:pointer" />
            </div>

            <div class="field-box withdrawApply">
                <label>手机号码</label><input class="span2 inline-input" readonly placeholder="请输入手机号码" value="@Model.MobilePhone" id="MobilePhone" name="MobilePhone" type="text" />
                <span class="btn-flat white" id="GetSmsCode">获取验证码</span>
            </div>
            <div class="field-box withdrawApply">
                <label>短信验证码:</label>
                <input class="span2 inline-input" placeholder="点击上方按钮获取短信验证码" id="PhoneCode" name="PhoneCode" type="text" /> 
                <span class="alert-msg"></span>
            </div>
            <div class="field-box withdrawApply">
                <label>新二级密码: </label><input class="form-control" type="password" id="NewPassWord" name="NewPassWord" placeholder="新二级密码" value="" />
                <span class="alert-msg"></span>
            </div>

            <div class="field-box withdrawApply">
                <label>确认二级密码: </label><input class="form-control" type="password" id="NewPassWordTwo" name="NewPassWordTwo" placeholder="新二级密码确认" value="" />
                <span class="alert-msg"></span>
            </div>

            <div class="span11 field-box actions">
                <label></label>
                <input type="button" class="btn-glow primary" id="btnSubmit" value="确认提交">

            </div>

        </div>
    </div>
</div>
@section scripts{
<script type="text/javascript">
        $(function () {
            //提示信息
            function SetTips(id, meg) {
                $("#" + id).next("span").html('<i class="icon-remove-sign"></i>' + meg);
                $("#" + id).next("span").show();
                $("#" + id).focus();

            }
            var codeClick = false;
            $("#GetSmsCode").click(function () {

            if (codeClick) {
                return;
            }

            var imgCode = $.trim($("#ImgCode").val());
            if (imgCode == '') {
                layer.msg('请输入图片验证码', { icon: 5 });
                $('#ImgCode').focus();
                return;
            }

            if (imgCode.length != 4) {
                layer.msg('图片验证码输入错误', { icon: 5 });
                $('#ImgCode').focus();
                return;
            }

            var Mobile = $("#MobilePhone").val();
            if (Mobile == '') {
                layer.msg('请输入手机号码', { icon: 5 });
                $('#MobilePhone').focus();
                return;
            }

            if (!validate.isMobile(Mobile)) {
                layer.msg('手机格式错误', { icon: 5 });
                $('#MobilePhone').focus();
                return;
            }

            //获取短信验证码
                $.post("/DrawingApi/SendMobileCode", { "Mobile": '@(Model.MobilePhone)', "SmsKey": "smsphonepwdvcode", "ImgCode": imgCode, "ImgCodeKey": "imgphonepwdvcode", SmsCode: "updatepwd2"  }, function (data) {
                if (data.IsSuccess) {
                    layer.msg('获取短信验证码成功', { icon: 5 });
                    codeClick = true;
                    var showText = '%s s重新获取';
                    var $this = $("#GetSmsCode");

                    if ($this.data('alt_button_disable_rendered') == 0) {
                        return false;
                    }
                    setTimeout(function () {
                        var count = 60;
                        setText();
                        $this.addClass("cur");
                        function setText() {
                            $this.html(showText.replace('%s', count));

                            if (count > 0) {
                                count--;
                                $this.data('alt_button_disable_rendered', 0);
                                setTimeout(setText, 1000);
                            } else {
                                codeClick = false;
                                $this.html('重新获取');
                                $this.data('alt_button_disable_rendered', 1);
                            }
                        }
                    }, 10);

                } else {
                    layer.msg(data.message, { icon: 5 });
                    return false;
                }

            });

            return;
        });


            //提交
            $("#btnSubmit").click(function () {
                $(".alert-msg").css("display", "none");

                var PhoneCode = $.trim($("#PhoneCode").val());
                var newPwd = $.trim($("#NewPassWord").val());
                var newPwd2 = $.trim($("#NewPassWordTwo").val());

                if (PhoneCode == '') {
                    SetTips('PhoneCode', "请输入短信验证码")
                    return;
                }
                if (newPwd == '') {
                    SetTips('NewPassWord', "请输入新二级密码")
                    return;
                }
                if (newPwd.length < 6) {
                    SetTips('NewPassWord', "二级密码必须大于等于6位数")
                    return;
                }

                if (newPwd2 == '') {
                    SetTips('NewPassWordTwo', "请再次输入新二级密码")
                    return;
                }
                if (newPwd != newPwd2) {
                    SetTips('NewPassWordTwo', "2次输入密码不一致")
                    return;
                }

                $.HM.ajax("Center/UpdatePass2", {
                    data: { 'PhoneCode': PhoneCode, "SmsKey": "smsphonepwdvcode",'newPwd': newPwd },
                    type: "POST",
                    dataType: 'json',
                    success: function (d) {
                        if (d.IsSuccess) {
                            layer.alert(d.message, { icon: 1 });
                        } else {
                            layer.msg(d.message, { icon: 0 });
                        }
                    }
                });

            });
        });
</script>
}